// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Eggman Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias 79 : TYPE_EGGMAN


// Static Values
public value WFZEggman_value51 = 0;

// Tables

event ObjectMain
	switch object.state
	case 0
		temp0 = object.xpos
		temp0 -= 0x200000
		if object[0].xpos > temp0
			temp0 = stage.newYBoundary2
			temp0 -= screen.ysize
			stage.newYBoundary1 = temp0
			if object.propertyValue == 1
				temp0 = object.ixpos
				temp0 -= 212
				stage.newXBoundary1 = temp0
			end if
			object.xpos += 0xE00000
			object[+1].type = TypeName[Eggman Barrier]
			object[+1].inkEffect = INK_ADD
			object[+2].type = TypeName[Eggman Barrier]
			object[+2].propertyValue = 1
			object[+2].inkEffect = INK_ADD
			object[+4].type = WFZEggman_value51
			ResetObjectEntity(26, TypeName[Music Event], 0, 0, 0)
			object[26].priority = PRIORITY_ACTIVE
			object.priority = PRIORITY_ACTIVE
			object.state = 1
		end if
		break
	case 1
		break
	case 2
		object.ypos += 0x10000
		object.value0++
		if object.value0 == 240
			stage.newYBoundary1 = 0
			object.type = TypeName[Blank Object]
			ResetObjectEntity(26, TypeName[Music Event], 1, 0, 0)
			object[26].priority = PRIORITY_ACTIVE
		end if
		break
	end switch
	object.animationTimer++
	if saveRAM[495] == 0
		if object.animationTimer >= 6
			object.animationTimer = 0
			object.frame ^= 1
		endif
	else
		if object.animationTimer >= 12
			object.animationTimer = 0
			object.frame ^= 1
		endif
	end if
end event


event ObjectDraw
	if object.state > 0
		DrawSprite(object.frame)
		DrawSprite(2)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone11")
	if checkResult == 1
			if saveRAM[495] == 0
				LoadSpriteSheet("SCZ/Objects.gif")
				SpriteFrame(-16, -28, 32, 52, 398, 203)
				SpriteFrame(-16, -27, 32, 51, 431, 204)
			else
				LoadSpriteSheet("SCZ/ObjectsE.gif")
				SpriteFrame(-16, -32, 32, 56, 398, 199)
				SpriteFrame(-16, -32, 32, 56, 431, 199)
			endif
		SpriteFrame(-32, 24, 64, 24, 1, 146)
		WFZEggman_value51 = TypeName[Eggman Laser]
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -28, 32, 52, 737, 58)
		SpriteFrame(-16, -27, 32, 51, 770, 58)
		SpriteFrame(-32, 24, 64, 24, 464, 999)
		WFZEggman_value51 = TypeName[Eggman Laser 3]
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
